#ifndef VIEWPORT_H
#define VIEWPORT_H
#include <ClanLib/core.h>
#include <ClanLib/display.h>

class Entity;

class Viewport
{
	// world_area: rectangle of viewport in world-space
	// screen_area: rectangle of viewport in screen-space
	// window_gc: double-pointer to the graphics context
	CL_Rect world_area, screen_area;
	CL_GraphicContext **window_gc;
	Entity *target;
	bool following;
	CL_Rect pan_bounds;

public:
	// constructor and destructor functions
	Viewport();
	Viewport(CL_Rect &world, CL_Rect &screen, CL_GraphicContext **displayWindow);
	Viewport(CL_Rect &world, CL_Rect &screen, CL_GraphicContext **displayWindow,
		 Entity &target, CL_Rect &bounds);
	~Viewport();

	// set following target
	void setTarget(Entity &newTarget);

	// clear following target
	void clearTarget();

	// update viewport to follow target 
	void update();

	// translate world coordinates represented by world_area to corresponding screen coordinates
	void worldToScreen(CL_Rect &world_area);

	// draw area of surface described by src to screen equivalent of world coordinates described by dest
	void draw(CL_Surface &surface, CL_Rect &src, CL_Rect dest);

	// draw area of surface described by src to background
	void draw(CL_Surface &surface, CL_Rect &src);

	// draw surface to background
	void draw(CL_Surface &surface);

	// draw sprite to screen equivalent of world coordinates described by dest
	void draw(CL_Sprite &sprite, CL_Rect dest);

	const CL_Rect &get_world_area();
	const CL_Rect &get_screen_area();
	CL_GraphicContext **get_window_gc();
};

#endif
